import { createBrowserRouter } from 'react-router-dom';
import { lazy } from 'react';
import Main from '../Layout/Main/Main';
import Manage from '../Layout/Manage/Manage';
import { Question } from '@/Layout/Question';
import { NotFound, Home, List, Login, Register, Star, Trash } from '@/pages';

const Edit = lazy(
  () => import(/* webpackChunkName: "editPage" */ '@/Layout/Question/Edit')
);
const Stat = lazy(
  () => import(/* webpackChunkName: "statPage" */ '@/Layout/Question/Stat')
);

const router = createBrowserRouter([
  {
    path: '/',
    element: <Main />,
    children: [
      {
        path: '/',
        element: <Home />,
      },
      {
        path: '/login',
        element: <Login />,
      },
      {
        path: 'register',
        element: <Register />,
      },
      {
        path: 'manage',
        element: <Manage />,
        children: [
          {
            path: 'list',
            element: <List />,
          },
          {
            path: 'star',
            element: <Star />,
          },
          {
            path: 'trash',
            element: <Trash />,
          },
        ],
      },
      {
        path: '*',
        element: <NotFound />,
      },
    ],
  },
  {
    path: 'question',
    element: <Question />,
    children: [
      {
        path: 'edit/:id',
        element: <Edit />,
      },
      {
        path: 'stat/:id',
        element: <Stat />,
      },
    ],
  },
]);

export default router;

export const HOME_PATH = '/';
export const LOGIN_PATH = '/login';
export const REGISTER_PATH = '/register';
export const MANAGE_LIST_PATH = '/manage/list';

export const isLoginOrRegisterPath = (pathname: string) =>
  pathname === LOGIN_PATH || pathname === REGISTER_PATH;

export const isNoNeedUserInfoPath = (pathname: string) =>
  pathname === LOGIN_PATH ||
  pathname === REGISTER_PATH ||
  pathname === HOME_PATH;
